package com.sys.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.sys.dao.DepartmentDao;
import com.sys.entity.Department;
import com.sys.service.DepartmentService;

@Service
public class DepartmentServiceImpl implements DepartmentService {
	@Resource
	private DepartmentDao departmentDao;

	@Override
	public Map<String, Object> pageListDepartment(String deptname, String description, String createtimeStart,
			String createtimeEnd, String updatetimeStart, String updatetimeEnd, Integer del, Integer page,
			Integer limit) {
		Map<String, Object> parmas = new HashMap<String, Object>();
		parmas.put("deptname", deptname);
		parmas.put("description", description);
		parmas.put("createtimeStart", createtimeStart);
		parmas.put("createtimeEnd", createtimeEnd);
		parmas.put("updatetimeStart", updatetimeStart);
		parmas.put("updatetimeEnd", updatetimeEnd);
		parmas.put("del", del);
		parmas.put("page", (page - 1) * limit);
		parmas.put("limit", limit);
		List<Department> department = departmentDao.pageListDepartment(parmas);
		int count = departmentDao.pageListDepartmentCount(parmas);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("list", department);
		map.put("count", count);
		return map;
	}

	@Override
	public int insertDepartment(String deptname, String description, String createtime, String updatetime,
			Integer del) {
		Department department = new Department();
		department.setCreatetime(createtime);
		department.setDel(del);
		department.setDeptname(deptname);
		department.setDescription(description);
		department.setUpdatetime(updatetime);
		return departmentDao.insertDepartment(department);
	}

	@Override
	public int updateDepartment(Integer deptid, String deptname, String description, String createtime,
			String updatetime, Integer del) {
		Department department = new Department();
		department.setCreatetime(createtime);
		department.setDeptid(deptid);
		department.setDel(del);
		department.setDeptname(deptname);
		department.setDescription(description);
		department.setUpdatetime(updatetime);
		return departmentDao.updateDepartment(department);
	}

	@Override
	public int deleteDepartment(Integer deptid) {
		Department department = new Department();
		department.setDeptid(deptid);
		return departmentDao.deleteDepartment(department);
	}

}
